home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / hdf / unix / examples.lha / examples / ann / putSDS_RISan.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-08  |  3.3 KB  |  107 lines

  1. #ifdef RCSID
  2. static char RcsId[] = "@(#)$Revision: 1.1 $";
  3. #endif
  4. /*
  5. $Header: /pita/work/HDF/dev/RCS/test/annotations/putSDS_RISan.c,v 1.1 90/04/19 11:16:15 mfolk beta $
  6.  
  7. $Log:    putSDS_RISan.c,v $
  8.  * Revision 1.1  90/04/19  11:16:15  mfolk
  9.  * Initial revision
  10.  * 
  11. */
  12. /***********************************************************
  13. *
  14. * Example program: Illustrates storing annotations in a file
  15. * Writes several SDSs and corresponding RISs to a file. 
  16. * Writes labels and descriptions for all but the first three SDSs.
  17. * Writes labels and descriptions for all RISs.
  18. *
  19. ************************************************************ */
  20.  
  21. #include <stdio.h>
  22. #include <math.h>
  23. #include "df.h"
  24. #define EXPAND 1
  25. #define TRUE   1
  26. #define FALSE  0
  27.  
  28. main(argc,argv)
  29. int argc;
  30. char *argv[];
  31. {
  32.     int i, j, k, l, height, width, reps, 
  33.         increment, imax;
  34.     int dimsizes[2];
  35.     float *pdata,*data,*hscale, *wscale, max, min;
  36.     char s[500], s1[200], label[50], outfile[50];
  37.     
  38.     if (argc != 5) {
  39.         printf("Usage: %s outfile height width reps\n", argv[0]);
  40.         exit(1);
  41.     }
  42.  
  43.     strcpy(outfile, argv[1]);
  44.     height = atoi(argv[2]);
  45.     width =  atoi(argv[3]);
  46.     reps = atoi(argv[4]);
  47.  
  48.     data = (float *) malloc(height*width*sizeof(float));
  49.     hscale = (float *) malloc(height*sizeof(float));
  50.     wscale = (float *) malloc(width*sizeof(float));
  51.  
  52.     gen2Dfloat(height, width, data, &max, &min);
  53.  
  54.     for (i=0; i< height; i++) hscale[i] = i+1;
  55.     for (i=0; i< width; i++)  wscale[i] = i+1;
  56.  
  57.     dimsizes[0]=width;
  58.     dimsizes[1]=height;
  59.  
  60.     i = DFSDsetdims(2,dimsizes);
  61.     i = DFSDsetmaxmin((float) max, min);
  62.     i = DFSDsetdimscale(1,height,hscale);
  63.     i = DFSDsetdimscale(2,width,wscale);
  64.  
  65.     for (j=0; j<reps; j++) {
  66.  
  67.         /* write out scientific data set */
  68.         DFSDadddata(outfile, 2,dimsizes,data);
  69.  
  70.         if ((j%3) != 0) {      /* write out annotations for 2 out of every 3 */
  71.             i = DFSDlastref();
  72.             sprintf(label,"Array #%d",j);
  73.             DFANputlabel(outfile, DFTAG_SDG, i, label);
  74.                sprintf(s,"2-D fp array #%d. Produces spectrum with grid.\n",j);
  75.                sprintf(s1,"\tDimensions:\n\t\theight = %d\n\t\twidth = %d", 
  76.                                                               height, width);
  77.                strcat(s,s1);
  78.             DFANputdesc(outfile, DFTAG_SDG, i, s, strlen(s));
  79.         } 
  80.  
  81.         /* convert data to image; write out image and its annotations */
  82.         DFUfptoimage(width,height, max, min, wscale,hscale,data,NULL,
  83.                                      outfile, EXPAND, width*5,height*5,FALSE);
  84.         i = DFR8lastref();
  85.         sprintf(label,"Image #%d",j);
  86.           DFANputlabel(outfile, DFTAG_RIG, i, label);
  87.         sprintf(s ,"Image #%d. Spectrum with grid.\n",j);
  88.            sprintf(s1,"\tDimensions:\n\t\theight = %d\n\t\twidth = %d", 
  89.                                                           height*5, width*5);
  90.            strcat(s ,s1);
  91.         DFANputdesc(outfile, DFTAG_RIG, i, s, strlen(s));
  92.          
  93.         pdata = data;       /* increment all data values by 2 */
  94.         increment = max/10;
  95.         imax = (float) max;
  96.         for (k=0; k< height; k++)    
  97.            for (l=0; l< width; l++) { 
  98.                *pdata = ( increment + (int) *pdata) % imax;
  99.                pdata++;
  100.            }
  101.     }
  102.  
  103.     printf("\n+++++++++++++++++++++++++\n\n");
  104.  
  105. }
  106.  
  107.